'''
Created on May 28, 2011

'''
from alpha_beta import INFINITY
from loa_game import BLACK, WHITE, TIE
class FramePenaltyUtil():
    def __init__(self,player):
        self.player = player
    
    def utility(self, state, ancestor):
#        winner = state.getWinner()
#        if winner == self.player:
#            return INFINITY-1
#        elif winner == TIE:
#            return 0
#        elif not winner is None:
#            return -1.0e40
        
        board = state.board
        
        penalty = 0;
        if self.player == WHITE:
            rows = board[0] + board[state.size-1]
            for cell in rows:
                if cell == WHITE:
                    penalty = penalty + 1
        else:
            for row in board:
                for col in 0,state.size-1:
                    if row[col] == BLACK:
                        penalty = penalty + 1
        
        return penalty